<%--
Created by IntelliJ IDEA.
User: wang
Date: 2021/3/16/016
Time: 18:36
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%--导入头部--%>
<%@include file="/common/headerAndLeft.jsp" %>



<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面----PageInfo</span>
    </div>
    <div class="search">
        <form action="${ctx}/user/userListPageInfo" method="post" id="searchForm" name="searchForm">
            <span>用户名：</span>
            <input type="text" placeholder="请输入用户名" name="userName" value="${param.userName}"/>
            <span>用户角色：</span>
            <select name="userRole">
                <option value="0">-----请选择-----</option>
                <c:forEach items="${roleList}" var="role">
                    <option value="${role.id}"
                            <c:if test="${param.userRole==role.id}">selected</c:if>
                    >${role.roleName}</option>
                </c:forEach>
            </select>
            <input type="hidden" name="pageNum" value="${pageInfo.pageNum}"/>
            <input type="hidden" name="pageSize" value="${pageInfo.pageSize}"/>
        </form>
        <%--<input type="reset" value="重置" id="reset1" style="width: 80px;height: 30px;text-align: center;vertical-align: center">--%>
        <input type="button" value="查询" id="btn1"/>
        <c:if test="${user.userRole!=3}">
            <a href="javaScript:void(0);" class="userAdd">添加用户</a>
        </c:if>


    </div>

    <!--用户-->
    <table class="providerTable" cellpadding="0" cellspacing="0">
        <tr class="firstTr">
            <th width="10%">用户编码</th>
            <th width="20%">用户名称</th>
            <th width="10%">性别</th>
            <th width="10%">出生日期</th>
            <th width="10%">电话</th>
            <th width="10%">用户类型</th>
            <th width="30%">操作</th>
        </tr>

        <c:if test="${empty pageInfo.list}">
            <tr>
                <td colspan="5" style="font-size: 16px">查询不到相关信息，请检查检索条件重新检索！</td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </c:if>
        <c:forEach items="${pageInfo.list}" var="user1" varStatus="counts">
            <tr <c:if test="${counts.count%2 eq 0}"> class="admin-list-td-h2" </c:if>>
                <td>${user1.userCode}</td>
                <td>${user1.userName}</td>
                <td>${user1.gender==1?"女":"男"}</td>
                <td>
                    <fmt:formatDate value="${user1.birthday}" pattern="yyyy-MM-dd"/>
                </td>
                <td>${user1.phone}</td>
                <td>${user1.userRoleName}</td>
                <td>
                    <c:choose>
                        <c:when test="${user.userRole==1}">
                            <a href="${ctx}/user/view/?id=${user1.id}"><img src="${ctx}/statics/images/read.png"
                                                                            alt="查看" title="查看"/></a>&nbsp;
                            <a href="javaScript:void(0)" id="${user1.id}" class="userUpdate"><img
                                    src="${ctx}/statics/images/xiugai.png" alt="修改" title="修改"/></a>&nbsp;
                            <c:if test="${user1.id!=user.id}">
                                <a href="javaScript:void(0)" class="removeUser" id="${user1.id}"><img
                                        src="${ctx}/statics/images/schu.png" alt="删除" title="删除"/></a></c:if>
                        </c:when>
                        <c:when test="${user.userRole==2}">
                            <c:if test="${user1.userRole==3||user1.id==user.id}">
                                <a href="${ctx}/user/view/?id=${user1.id}"><img src="${ctx}/statics/images/read.png"
                                                                                alt="查看" title="查看"/></a>&nbsp;
                                <a href="javaScript:void(0)" id="${user1.id}" class="userUpdate"><img
                                        src="${ctx}/statics/images/xiugai.png" alt="修改" title="修改"/></a>&nbsp;
                                <c:if test="${user1.id!=user.id}">
                                    <a href="javaScript:void(0)" class="removeUser" id="${user1.id}"><img
                                            src="${ctx}/statics/images/schu.png" alt="删除" title="删除"/></a></c:if>
                            </c:if>
                            <c:if test="${user1.userRole!=3 && user1.id!=user.id}">没有权限操作</c:if>
                        </c:when>
                        <c:when test="${user.userRole==3}">
                            <c:if test="${user1.id==user.id}">
                                <a href="${ctx}/user/view/?id=${user1.id}"><img src="${ctx}/statics/images/read.png"
                                                                                alt="查看" title="查看"/></a>&nbsp;
                                <a href="javaScript:void(0)" id="${user1.id}" class="userUpdate"><img
                                        src="${ctx}/statics/images/xiugai.png" alt="修改" title="修改"/></a>&nbsp;

                            </c:if>
                            <c:if test="${user1.id!=user.id}">没有权限操作</c:if>
                        </c:when>
                    </c:choose>


                </td>
            </tr>
        </c:forEach>


    </table>
    <%--分页条--%>
    <div class="pageNav" style="margin-top: 50px">
        <c:import url="/common/pageNavPageHelper.jsp">
            <c:param name="pageNum" value="${pageInfo.pageNum}"></c:param>
            <c:param name="pageSize" value="${pageInfo.pageSize}"></c:param>
            <c:param name="total" value="${pageInfo.total}"></c:param>
            <c:param name="pages" value="${pageInfo.pages}"></c:param>
        </c:import>
    </div>

    <div class="userUpdateView"></div>
    <div class="userAddView"></div>
    <div>
        <br/><br/>
        <button onclick="location.href='${ctx}/user/exportUserLists'">导出用户数据</button>
        <br/><br/>
        <button onclick="location.href='${ctx}/user/downloadUserDemo'">下载模板</button>
        <br/><br/>
        <form method="post" enctype="multipart/form-data" action="${ctx}/user/uploadUserInfo" id="excelForm">
            上传Excel导入用户数据：<input type="file" name="myFile" id="myFile">
            <input type="submit" value="文件上传" style="width: 110px">
        </form>
    </div>
    <div>
        <a href="${ctx}/user/userListAll">查询所有用户</a>
    </div>
    <div class="addView"></div>


</div>

</section>
<%--Excel xslx、xsl后缀文档上传验证--%>
<script type="text/javascript">
    $(function () {
        $("#excelForm").submit(function () {
            var fileName = $("#myFile").val();
            if (fileName == null || fileName == "") {
                alert("请选择上传文件！")
                return false;
            } else if (fileName.indexOf(".") == -1) {
                alert("文件必须要有后缀名!");
                return false;
            } else if (fileName.substring(fileName.indexOf(".") + 1) != "xlsx" && fileName.substring(fileName.indexOf(".") + 1) != "xls") {
                alert("文件格式不正确，必须是xlsx或者xls！");
                return false;
            } else {
                return true;
            }

        });
    });
</script>

<%--userAdd--%>
<script type="text/javascript">
    $(function () {
        $(".userAdd").click(function () {
            $(".addVIew").load(
                "${ctx}/user/toUserAdd"
            );
        });
    });
</script>

<%--userUpdate--%>
<script type="text/javascript">
    $(function () {
        $(".userUpdate").click(function () {
            $(".addVIew").load(
                "${ctx}/user/toUserUpdate",
                {"id": $(this).attr("id")}
            );
        });
    });
</script>

<%--条件分页查询按钮提交--%>
<script type="text/javascript">
    $(function () {
        $("#btn1").click(function () {
            //alert(11111);
            $("#searchForm").submit();
        });
    });
</script>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeUse">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该用户吗？</p>
            <a id="yesUser" href="javaScript:void(0);">确定</a>
            <a id="no">取消</a>
        </div>
    </div>
</div>


<footer class="footer">
    版权归北大青鸟
</footer>


</body>
</html>